package com.googlecode.milib.display.button {
	import com.googlecode.milib.display.button.AbstractButton;
	import com.googlecode.milib.vo.MLEvent;
	
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;		

	/**
	 * @author Marek Brun
	 */
	public class MultipleButtonsAsOne extends AbstractButton {

		private var outTimer:Timer;
		
		public function MultipleButtonsAsOne(buttons:Array, outTimeout:uint=250) {
			var i:uint;
			var loop:AbstractButton;
			for(i=0;i<buttons.length;i++){
				loop=buttons[i];
				loop.addEventListener(loop.event_Over, onButton_Over);				loop.addEventListener(loop.event_Out, onButton_Out);				loop.addEventListener(loop.event_Press, onButton_Press);
			}
			
			outTimer=new Timer(Number(outTimeout), 1);
			outTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onOutTimer);
			
		}

		//********************************************************************************************
		//		events for MultipleButtonsAsOne
		//********************************************************************************************
		protected function onButton_Over(event:MLEvent):void {
			outTimer.stop();
			setRollOver();
		}
		
		protected function onButton_Out(event:MLEvent):void {
			outTimer.reset();			outTimer.start();
		}

		protected function onButton_Press(event:MLEvent):void {
			setPress();
		}
		
		protected function onOutTimer(event:Event):void {
			setRollOut();
		}
		
	}
}
